package com.aw.jsr303.ejemplo001;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * User: gmc
 * Date: 30/06/2010
 */
public class OnlyLettersValidator implements ConstraintValidator<OnlyLetters, String> {

    public void initialize(OnlyLetters annotation) {
    }

    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        return allAreLetters(value);
    }

    private boolean allAreLetters(String str) {
        if (str == null) {
            return false;
        }
        int stringSize = str.length();
        for (int i = 0; i < stringSize; i++) {
            if (Character.isLetter(str.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }
}

